Walkthrough 2-3: Create an integration application with Flow Designer that consumes an API
In this walkthrough, you build an integration application to consume an API from Anypoint Exchange. You will:
· Examine Mule event data for calls to an application.
· Use the Training: American Flights API in Anypoint Exchange to get all flights.
· Transform data returned from an API to another format.
Review Mule event data for the calls to the application
1. Return to the American Flights App in Flow Designer.
2. Click the down arrow in the upper-right corner of the Logs panel to close it.
3. Click the HTTP Listener card to expand it.
4. Select the Output tab.
5. Locate the Show drop-down menu that currently has Payload selected.
6. Locate your two calls to the application in the History panel; there should be no event payload for either call.
7. Change the Show drop-down menu to Attributes.
8. Review the attributes for the Mule event leaving the HTTP Listener processor.
9. Close the card.
10. Expand the Logger card.
11. Select the Input tab.
12. Review the payload and attributes values for the two calls.
Note: You may see less than two calls for the Logger.
13. Select the Output tab and review the payload and attributes values for the calls.
Delete a card
14. Click the options menu for the Logger card and select Delete.
Use Training: American Flights API in Anypoint Exchange to get all flights
15. Click the Add button next to the HTTP Listener card.
16. In the Select a component dialog box, select the Training: American Flights API.
17. In the Training: American Flights API > Select an operation dialog box, select Get Flights.
Configure the American Flights API to use a secured endpoint
18. In the American Flights API Configuration dialog box, click Add connection.
19. In the Configuration Connection dialog box, set the connection name to American Flights, select Connection in the connection type drop-down menu, then click Save.
20. In the American Flights API Configuration dialog box, select the American Flights API connection, set the host, port, base path, and protocol values to the values listed in the course snippets.txt file and click Save:
21. In the Get Flights dialog box, copy and paste the client_id and client_secret values from the course snippets.txt file.
22. Close the American Flights API card.
23. Click the Test button in the main menu bar.
24. Wait until the application is running.
Test the application
25. Return to Advanced REST Client and click Send; you should see flight data.
26. Click Send again to make a second request.
Review Mule event data
27. Return to Flow Designer and open the American Flights API card.
28. Select the Input tab and examine the Mule event data.
29. Select the Output tab; you should see payload data.
30. Close the card.
Add and configure a component to transform the data
31. Click the add button in the flow.
32. In the Select a component dialog box, select Transform.
33. In the Transform card, look at the Mule event structure in the input section.
34. In the output section, click the Create new Data Type button.
35. In the New Type dialog box, set the following values:
· Name: Flights
· Format: JSON
· Type: From example
36. In the computer's file explorer, return to the student files folder and locate the flights-example.json file in the resources/examples folder.
37. Open the file in a text editor and copy the code.
38. Return to Flow Designer and add your JSON example by pasting the code in the section replacing any existing code.
39. Click Save.
40. In the input section, expand the plane object.
Create the transformation
41. Map fields with the same names by dragging them from the input section and dropping them on the corresponding field in the output section.
· price to price
· departureDate to departureDate
· plane > totalSeats to totalSeats
· emptySeats to emptySeats
42. Map fields with different names by dragging them from the input section and dropping them on the corresponding field in the output section.
· plane > type to planeType
· code to flightCode
· origin to fromAirportCode
· destination to toAirportCode
43. In the output section, click the options menu for the airline field and select Set Expression.
44. Change the value from null to "american" and click OK.
45. Click the Script tab at the bottom of the card; you should see the DataWeave expression for the transformation.
Note: You learn to write DataWeave transformations later in the Development Fundamentals course.
Add sample data
46. Click the Sample data tab in the preview section.
47. In the computer's file explorer, return to the student files folder and locate the american-flights-example.json file in the resources/examples folder.
48. Open the file in a text editor and copy the code.
49. Return to Flow Designer and paste the code in the sample data for payload section.
50. Look at the preview section, you should see a sample response for the transformation.
51. Close the card.
Locate the data type and configuration definitions
52. Locate the connector configuration and the new Flights data type in the project explorer.
Test the application
53. Click the Test button again and wait for the application to run.
54. Return to Advanced REST Client and click Send to make another request to http://americanflightsapp-xxxx.{region}.cloudhub.io/flights; you should see all the flight data as JSON again but now with a different structure.
Stop the application
55. Return to Runtime Manager.
56. In the left-side navigation, click Applications.
57. Select the row with your application; you should see information about the application displayed on the right side of the window.
58. Click the drop-down menu button next to Started and select Stop; the status should change to Undeployed.
Note: You can deploy it again from Flow Designer when or if you work on the application again.
59. Close Runtime Manager.
60. Return to Flow Designer; you should see the application is not running and needs to be refreshed.
61. Return to Design Center.